import './config'
import Vue from 'vue'
import App from './App.vue'
import Storage from 'vue-ls'
import router from './router'
import store from './store/'
import start from "./micro"

import {
  VueAxios
} from "@/utils/request"
import { FormModel } from 'ant-design-vue';
/** init domain config */

import {
  getAction,
  postFormAction,
  postAction
} from "@/api/manage"

if (process.env.NODE_ENV !== 'prod') {
  require('@jeecg/antd-online-mini')
  require('@jeecg/antd-online-mini/dist/OnlineForm.css')
}


import Antd, {
  version
} from 'ant-design-vue'
console.log('ant-design-vue version:', version)

import Viser from 'viser-vue'
import 'ant-design-vue/dist/antd.less'; // or 'ant-design-vue/dist/antd.less'

import '@/permission' // permission control
import '@/utils/filter' // base filter
import Print from 'vue-print-nb-jeecg'
/*import '@babel/polyfill'*/
import preview from 'vue-photo-preview'
import 'vue-photo-preview/dist/skin.css'
import SSO from '@/cas/sso.js'
import {
  ACCESS_TOKEN,
  DEFAULT_COLOR,
  DEFAULT_THEME,
  DEFAULT_LAYOUT_MODE,
  DEFAULT_COLOR_WEAK,
  SIDEBAR_TYPE,
  DEFAULT_FIXED_HEADER,
  DEFAULT_FIXED_HEADER_HIDDEN,
  DEFAULT_FIXED_SIDEMENU,
  DEFAULT_CONTENT_WIDTH_TYPE,
  DEFAULT_MULTI_PAGE
} from "@/store/mutation-types"
import config from '@/defaultSettings'

import JDictSelectTag from './components/dict/index.js'
import hasPermission from '@/utils/hasPermission'
import vueBus from '@/utils/vueBus';
import JeecgComponents from '@/components/jeecg/index'
import '@/assets/less/JAreaLinkage.less'
import VueAreaLinkage from 'vue-area-linkage'
import '@/components/jeecg/JVxeTable/install'
import '@/components/JVxeCells/install'
import VueI18n from 'vue-i18n'
import zh_CN from '@/components/lang/zh_CN.js'    // 引入lang文件
import en_US from '@/components/lang/en_US.js'
import XLSX from 'xlsx'

//流程相关



import Modal from 'ant-design-vue/lib/modal/index'//弹框
import echarts from './utils/echart.config'

import dataV from '@jiaminghi/data-view';


Vue.use(VueI18n)
Vue.config.productionTip = false
Vue.use(Storage, config.storageOptions)
Vue.use(Antd)
Vue.use(VueAxios, router)
Vue.use(Viser)
Vue.use(hasPermission)
Vue.use(JDictSelectTag)
Vue.use(Print)
Vue.use(preview)
Vue.use(vueBus);
Vue.use(JeecgComponents);
Vue.use(VueAreaLinkage);
Vue.use(FormModel);

Vue.use(dataV);

// 挂载全局使用的方法
Vue.prototype.doMian = "/jks-dcp";
Vue.prototype.postFormAction = postFormAction;
Vue.prototype.postDataAction = postAction;
Vue.prototype.getAction = getAction;
Vue.prototype.$modal = Modal
Vue.prototype.$echarts = echarts

//生成表格的方法x
const ToDoExcel = (excelName, titleArr, dataArr) => {
  var filename = excelName + ".xlsx" //文件名称
  var data = [titleArr, ...dataArr]  //数据，一定注意需要时二维数组
  var ws_name = "Sheet1" //Excel第一个sheet的名称
  var wb = XLSX.utils.book_new(), ws = XLSX.utils.aoa_to_sheet(data)
  XLSX.utils.book_append_sheet(wb, ws, ws_name)  //将数据添加到工作薄
  XLSX.writeFile(wb, filename)
}
Vue.prototype.$ToDoExcel = ToDoExcel

// 注册i18n实例并引入语言文件，文件格式等下解析
const i18n = new VueI18n({
  locale: Vue.ls.get("lang", "CN"),
  fallbackLocale: 'US',
  silentFallbackWarn: true,
  messages: {
    'zh-CN': { ...zh_CN },
    'en-US': { ...en_US }
  }
})

// SSO.init(() => {
  main()
// })

function handleSetLanguage(lang) {
  this.$i18n.locale = lang; //改变当前语言
  Vue.ls.set("language", lang);//将lang 语言存在localStorage里，main里面就会根据属性值进行判断 locale: Vue.ls.get("language", "zh-CN")
}

function main() {
  new Vue({
    router,
    store,
    i18n,
    mounted() {
      store.commit('SET_SIDEBAR_TYPE', Vue.ls.get(SIDEBAR_TYPE, true))
      store.commit('TOGGLE_THEME', Vue.ls.get(DEFAULT_THEME, config.navTheme))
      store.commit('TOGGLE_LAYOUT_MODE', Vue.ls.get(DEFAULT_LAYOUT_MODE, config.layout))
      store.commit('TOGGLE_FIXED_HEADER', Vue.ls.get(DEFAULT_FIXED_HEADER, config.fixedHeader))
      store.commit('TOGGLE_FIXED_SIDERBAR', Vue.ls.get(DEFAULT_FIXED_SIDEMENU, config.fixSiderbar))
      store.commit('TOGGLE_CONTENT_WIDTH', Vue.ls.get(DEFAULT_CONTENT_WIDTH_TYPE, config.contentWidth))
      store.commit('TOGGLE_FIXED_HEADER_HIDDEN', Vue.ls.get(DEFAULT_FIXED_HEADER_HIDDEN, config.autoHideHeader))
      store.commit('TOGGLE_WEAK', Vue.ls.get(DEFAULT_COLOR_WEAK, config.colorWeak))
      store.commit('TOGGLE_COLOR', Vue.ls.get(DEFAULT_COLOR, config.primaryColor))
      store.commit('SET_TOKEN', Vue.ls.get(ACCESS_TOKEN))
      store.commit('SET_MULTI_PAGE', Vue.ls.get(DEFAULT_MULTI_PAGE, config.multipage))
    },
    render: h => h(App)
  }).$mount('#app')
  start()
}